package com.yyh.fanshe;

import java.lang.reflect.Constructor;

public class Demo3 {
    public static void main(String[] args) throws Exception {
        //1.获取Class对象
        Class clas1 = Class.forName("com.yyh.fanshe.User");
        //2.获取公共的无参构造
        Constructor cons1 = clas1.getConstructor();
        System.out.println("cons1 = " + cons1);
        //获取公共的满参构造
        Constructor cons2 = clas1.getConstructor(String.class, int.class, String.class,String.class);
        System.out.println("cons2 = " + cons2);
        //3.获取所有的公共的构造方法
        Constructor[] constructors = clas1.getConstructors();
        for (Constructor constructor : constructors) {
            System.out.println("constructor = " + constructor);
        }
        //4.获取所有的构造方法
        Constructor[] declaredConstructors = clas1.getDeclaredConstructors();
        for (Constructor constructor : declaredConstructors) {
            System.out.println("constructor = " + constructor);
        }
    }
}
